#include <stdio.h>

void print(int *data, int len)
{
	int i = 0;
	for (; i < len; ++i) {
		printf("%d ", data[i]);
	}
	printf("\n");
}

void quicksort(int *data, int left, int right)
{
	int i=left;
	int j=right;
	int k = data[i];

	printf("left(%d) right(%d)\n", left, right);

	while (i < j) {
		for (; j>i && k <= data[j]; --j) {}
		data[i] = data[j];
		for (; j>i && k >= data[i]; ++i) {}
		data[j] = data[i];
	}

	data[i] = k;

	print(data, 9);
	if (i-1 > left) {
		quicksort(data, left, i-1);
	}
	if (right > i+1) {
		quicksort(data, i+1, right);
	}
}


int main(int argc, char const* argv[])
{
	int d[] = {6, 2, 3, 7, 16, 3, 6, 8, 9};
	print(d, 9);
	quicksort(d, 0, 9);
	print(d, 9);

	
	return 0;
}
